package com.loukou.lkt.lkt.redis;

import java.util.concurrent.TimeUnit;

import org.springframework.stereotype.Repository;

import com.loukou.lkt.lkt.resp.AuthInfo;


@Repository
public class RedisService extends RedisDao {

	public AuthInfo getAuthInfo(String sessionId){
		return (AuthInfo) valueOperations.get(sessionId);
	}
	
	public boolean setAuthInfo(AuthInfo authInfo){
		deleteAuthInfo(authInfo.getSessionId());
		valueOperations.set(authInfo.getSessionId(), authInfo);
		redisTemplate.expire(authInfo.getSessionId(), 1, TimeUnit.HOURS);
		return true;
	}
	
	public boolean deleteAuthInfo(String sessionId){
		if(getAuthInfo(sessionId)==null){
			return true;
		}
		redisTemplate.delete(sessionId);
		return true;
	}
}
